package com.example.analysis.controller;

import com.example.analysis.service.UserService;
import com.example.analysis.utils.Response;
import com.example.analysis.vo.UserVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    private UserService userService;
    private @PostMapping("/login")
    Response<String> login(@RequestBody UserVO user) {
        System.out.println(user);
        boolean login = userService.login(user);
        int code = login ? 20000 : 50001;
        String data = login ? user.getUsername() + "+" + user.getRole() : null;
        String msg = login ? "登录成功" : "登录失败";
        return new Response<>(true, msg, data, code);
    }

    @GetMapping("/info")
    Response<UserVO> info(String token) {
        UserVO userVO = userService.getInfo(token);
        return new Response<>(true, "info", userVO, 20000);
    }

    @PostMapping("/logout")
    Response<String> logout() {
        return new Response<>(true, "logout success!!!", "logout", 20000);
    }
}
